//***************************************************************************************
// MediaFrame is an Open Source streaming media platform in Java 
// which provides a fast, easy to implement and extremely small applet 
// that enables to view your audio/video content without having 
// to rely on external player applications or bulky plug-ins.
//
//--------------------------------------------------------------------------------------
//
// We changed a lot of code and added a lot of functionality.
// This includes, but not limited to, the following changes:
// 1. The project was renamed to MediaFrame;
// 2. The connection speed detection procedure was added;
// 3. The JavaScript API functions were added;
// 4. The pre and post image support functionality was added;
// 5. The ability to save movie into the local disk was added;
// 6. The inner buffer for a movie file was added;
// 7. The click-through functionality was added;    
// 8. The .zip files support was added;    
// 9. The realtime feedback agent functionality was added.    
// For the full list of the current functionality please visit the following web page:
// http://mediaframe.org/
//    
// 06 Jul 2002 - 19 Dec 2004 Konstantin Belous, Oleg Lebedev
//
//--------------------------------------------------------------------------------------
//
//								"motion_data.java"
//
// This file contains the class "motion_data" which is used to store and compute the
// motion information. Two objects of this class are created: One for forward and
// one for backward prediction.
//
// To understand the methods refer also to ISO 11172-2!
//
//--------------------------------------------------------------------------------------
//
//		Joerg Anders, TU Chemnitz, Fakultaet fuer Informatik, GERMANY
//		ja@informatik.tu-chemnitz.de
//
//
//--------------------------------------------------------------------------------------
//
// This program is free software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this
// program; (See "LICENSE.GPL"). If not, write to the Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//--------------------------------------------------------------------------------------
//
// If the program runs as Java applet it isn't "interactive" in the sense of the GNU
// General Public License. So paragraph 2c doesn't apply.
//
//***************************************************************************************

package mediaframe.mpeg1;

/**
 * The <code>motion_data</code> class is used to store and compute the motion information. 
 * Two objects of this class are created: One for forward and one for backward prediction.
 */
public class motion_data {
	/** The value of the horizontal part of the previous motion vector. */
	private int recon_right_x_prev = 0;
	/** The value of the vertical part of the previous motion vector. */
	private int recon_down_x_prev = 0;
	/** The value of the horizontal part value of the motion vector. */
	private int recon_right_x = 0; 
	/** The value of the vertical part of the motion vector. */
	private int recon_down_x = 0;
	/** The integer part of the horizontal part of the motion vector for the luminance blocks. */
	private int right_x = 0;
	/** The integer part of the vertical part of the motion vector for the luminance blocks. */
	private int down_x = 0;
	/** <tt>True</tt>, if the fractional part > 0 of the horizontal part of the motion vector for the luminance blocks. */
	private boolean right_half_x = false;
	/** <tt>True</tt>, if the fractional part > 0 of the vertical part of the motion vector for the luminance blocks. */
	private boolean down_half_x = false;	 
	/** The integer part of the horizontal part of the motion vector for the chrominance blocks. */
	private int right_x_col = 0;
	/** The integer part of the vertical part of the motion vector for the chrominance blocks. */
	private int down_x_col = 0;
	/** <tt>True</tt>, if the fractional part > 0 of the horizontal part  of the motion vector for the chrominance blocks. */
	private boolean right_half_x_col = false;
	/** <tt>True</tt>, if the fractional part > 0 of the vertical part of the motion vector for the chrominance blocks. */
	private boolean down_half_x_col = false;	 
	/** The size of the motion data. */
	private int x_ward_f = 0;
	/** The min value of the motion vector. */
	private int min = 0;
	/** The max value of the motion vector. */
	private int max = 0;
	/** The range (equals to max - min) of the motion vector. */
	private int range = 0;
	/** Equals <tt>true</tt> if full pixel accuracy is used, equals <tt>false</tt>, if half pixel accuracy is used. */
	private boolean Full_pel_x_vector = true;

	/** The current number of printed errors in motion_data. */
	private int error_count = 0;
	
	/** The number of pixels per luminance line. */
	private int pixel_per_lum_line;
	/** The number of pixels per colour line. */
	private int pixel_per_col_line;
	/** The increment for the luminance line, equals to pixel_per_lum_line - 8. */
	private int lum_y_incr;
	/** The increment for the luminance line, equals to pixel_per_col_line - 8. */
	private int col_y_incr;

	/**
	 * The method "init" is called by the "MPEG_video" as soon as the MPEG
	 * dimensions are known.
	 * @param f_pixel_per_lum_line the number of pixels per luminance line.
	 * @param f_pixel_per_col_line the number of pixels per colour line.
	 * @param f_lum_y_incr the increment for the luminance line, equals to f_pixel_per_lum_line - 8.
	 * @param f_col_y_incr the increment for the luminance line, equals to f_pixel_per_col_line - 8.
	 */

	public final void init (int f_pixel_per_lum_line, int f_pixel_per_col_line, int f_lum_y_incr, int f_col_y_incr) {
		pixel_per_lum_line = f_pixel_per_lum_line;
		pixel_per_col_line = f_pixel_per_col_line;
		lum_y_incr = f_lum_y_incr;
		col_y_incr = f_col_y_incr;
	}

	/**
	 * The method "set_pic_data" is called from "MPEG_video" as soon as
	 * the size of the motion data is given.
	 * @param f the size of the motion data. 
	 * @param Full equals <tt>true</tt> if full pixel accuracy is used, equals <tt>false</tt>, if half pixel accuracy is used.
	 */

	public final void set_pic_data(int f, boolean Full) {
		x_ward_f = f; Full_pel_x_vector = Full;
		range = f << 5;
		max = (f << 4) - 1;
		min = -(f << 4);
	}

	/**
	 * In some situations it is necessary to reset the motion data.
	 * Therefore a method "reset_prev" is implemented.
	 */

	public final void reset_prev() {
		recon_right_x_prev = recon_down_x_prev = 0;
	}

	/**
	 * The internal method "motion_displacement" computes the difference of the
	 * actual motion vector in respect to the last motion vector. 
	 * @param motion_code the motion code value for prediction. 
	 * @param PMD the motion displacement value of the previous motion vector. 
	 * @param motion_r the motion residual value. 
	 * @return the motion vector value.
	 */
	/* Refer to ISO 11172-2 to understand the coding of the motion displacement. */
	private final int motion_displacement(int motion_code, int PMD, int motion_r) {
		int dMD, MD;
	
		if (x_ward_f == 1 || motion_code == 0) {
			dMD = motion_code;
		}
		else {
			dMD = 1 + x_ward_f * (Math.abs(motion_code) - 1);
			dMD += motion_r;
			if (motion_code < 0) dMD = -dMD;
		}
		MD = PMD + dMD;
		if (MD > max) MD -= range;
		else if (MD < min) MD += range;
		return MD;
	}

	/**
	 * The method "compute_motion_vector" computes the motion vector according to the
	 * values supplied by the "MPEG_video". It uses the method "motion_displacement".
	 * The result are the motion vectors for the luminance and the chrominance blocks.
	 * @param motion_horiz_x_code the motion code value of horizontal part for prediction.
	 * @param motion_verti_x_code the motion code value of vertial part for prediction.
	 * @param motion_horiz_x_r the motion residual value of horizontal part for prediction.
	 * @param motion_verti_x_r the motion residual value of vertial part for prediction.
	 */

	public final void compute_motion_vector(int motion_horiz_x_code, int motion_verti_x_code,
											int motion_horiz_x_r, int motion_verti_x_r) {

		recon_right_x_prev = recon_right_x = 
		motion_displacement(motion_horiz_x_code, recon_right_x_prev, motion_horiz_x_r);
		if (Full_pel_x_vector) recon_right_x <<= 1;
		recon_down_x_prev = recon_down_x = 
		motion_displacement(motion_verti_x_code, recon_down_x_prev, motion_verti_x_r);
		if (Full_pel_x_vector) recon_down_x <<= 1;

		right_x = recon_right_x >> 1;
		down_x  = recon_down_x  >> 1;
		right_half_x = (recon_right_x & 0x1) != 0;
		down_half_x  = (recon_down_x  & 0x1) != 0;

		right_x_col = recon_right_x >> 2;
		down_x_col  = recon_down_x >> 2;
		right_half_x_col = (recon_right_x & 0x2) != 0;
		down_half_x_col  = (recon_down_x & 0x2) != 0;
	}

	/**
	 * The method "get_area" grabs the area determined by the motion
	 * vector from "src" and puts it to the temporary storage "dst". If
	 * the motion vectors define half steps the method follows the
	 * instructions given in ISO 11172-2.
	 * @param mb_row the row of the left top corner of the area to grab.
	 * @param mb_column the column of the left top corner of the area to grab.
	 * @param src the source YUV frame. 
	 * @param dst the destination YUV frame.
	 */

	public final void get_area(int mb_row, int mb_column, int src[][], int dst[]) {

		try {

		int pos, pos1, i;
		int j, pos2, pos3, dst_pos = 0;
		int ypos = (mb_row << 4) + down_x;
		int xpos = (mb_column << 4) + right_x;
		int pos_c, pos1_c, pos2_c, pos3_c;

		// Loop invariant elimination
		int[] src0 = src[0];
		int[] src1 = src[1];
		int[] src2 = src[2];

		// LUMINACE:

		if (!right_half_x && !down_half_x) {
			pos = pixel_per_lum_line * ypos + xpos;
			for (j = 16; j > 0; j--) {
				System.arraycopy(src0, pos, dst, dst_pos, 16);
				pos += pixel_per_lum_line; dst_pos += 16;
			}
		}
		else if (!right_half_x && down_half_x)  {
			pos = pixel_per_lum_line * ypos + xpos;
			pos1 = pixel_per_lum_line * (ypos + 1) + xpos;
			for (j = 16; j > 0; j--) {
				for (i = 16; i > 0; i--) {
					dst[dst_pos++] = (src0[pos++] + src0[pos1++]) >> 1;
				}
				pos += lum_y_incr; pos1 += lum_y_incr;
			}
		}
		else if (right_half_x && !down_half_x) {
			pos = pixel_per_lum_line * ypos + xpos;
			pos1 = pixel_per_lum_line * ypos + xpos + 1;
			for (j = 16; j > 0; j--) {
				for (i = 16; i > 0; i--) {
					dst[dst_pos++] = (src0[pos++] + src0[pos1++]) >> 1;
				}
				pos += lum_y_incr; pos1 += lum_y_incr;
			}
		}
		else {
			pos = pixel_per_lum_line * ypos + xpos;
			pos1 = pixel_per_lum_line * (ypos + 1) + xpos;
			pos2 = pixel_per_lum_line * ypos + xpos + 1;
			pos3 = pixel_per_lum_line * (ypos + 1) + xpos + 1;
			for (j = 16; j > 0; j--) {
				for (i = 16; i > 0; i--) {
					dst[dst_pos++] = (src0[pos++] + src0[pos1++] +
							  src0[pos2++] + src0[pos3++]) >> 2;
				}
				pos += lum_y_incr; pos1 += lum_y_incr; pos2 += lum_y_incr; pos3 += lum_y_incr;
			}
		}


		// CHROMINANCE:

		ypos = (mb_row << 3) + down_x_col;
		xpos = (mb_column << 3) + right_x_col;


		if (!right_half_x_col && !down_half_x_col) {
			pos = pixel_per_col_line * ypos + xpos;
			for (j = 8; j > 0; j--) {
				System.arraycopy(src1, pos, dst, dst_pos, 8);
				dst_pos += 8;
				System.arraycopy(src2, pos, dst, dst_pos, 8);
				dst_pos += 8;
				pos += pixel_per_col_line;
			}
		}
		else if (!right_half_x_col && !down_half_x_col) {
			pos = pixel_per_col_line * ypos + xpos;
			pos1 = pixel_per_col_line * (ypos + 1) + xpos;
			for (j = 8; j > 0; j--) {
				pos_c = pos; pos1_c = pos1;
				for (i = 8; i > 0; i--) {
					dst[dst_pos++] = (src1[pos++] + src1[pos1++]) >> 1;
				}
				for (i = 8; i > 0; i--) {
					dst[dst_pos++] = (src2[pos_c++] + src2[pos1_c++]) >> 1;
				}
				pos += col_y_incr; pos1 += col_y_incr;
			}
		}
		else if (right_half_x_col  && !down_half_x_col) {
			pos_c = pos = pixel_per_col_line * ypos + xpos;
			pos1_c = pos1 = pixel_per_col_line * ypos + xpos + 1;
			for (j = 8; j > 0; j--) {
				pos_c = pos; pos1_c = pos1;
				for (i = 8; i > 0; i--) {
					dst[dst_pos++] = (src1[pos++] + src1[pos1++]) >> 1;
				}
				for (i = 8; i > 0; i--) {
					dst[dst_pos++] = (src2[pos_c++] + src2[pos1_c++]) >> 1;
				}
				pos += col_y_incr; pos1 += col_y_incr;
			}
		}
		else {
			pos_c = pos = pixel_per_col_line * ypos + xpos;
			pos1_c = pos1 = pixel_per_col_line * (ypos + 1) + xpos;
			pos2_c = pos2 = pixel_per_col_line * ypos + xpos + 1;
			pos3_c = pos3 = pixel_per_col_line * (ypos + 1) + xpos + 1;
			for (j = 8; j > 0; j--) {
				pos_c = pos; pos1_c = pos1; pos2_c = pos2; pos3_c = pos3;
				for (i = 8; i > 0; i--) {
					dst[dst_pos++] = (src1[pos++] + src1[pos1++] + src1[pos2++] + src1[pos3++]) >> 2;
				}
				for (i = 8; i > 0; i--) {
					dst[dst_pos++] = (src2[pos_c++] + src2[pos1_c++] + src2[pos2_c++] + src2[pos3_c++]) >> 2;
				}
				pos += col_y_incr; pos1 += col_y_incr; pos2 += col_y_incr; pos3 += col_y_incr;
			}
		}

		} catch (Exception e) {
			error_count++;
			if (error_count < 5)
				System.out.println("Illegal area get...");
			else if (error_count == 5)
				System.out.println("Ignoring further errors in motion_data...");
		}

	}

	/**
	 * The method "copy_area" grabs the area determined by the motion
	 * vector from "src" and puts it to the destination storage "dst". If
	 * the motion vectors define half steps the method follows the
	 * instructions given in ISO 11172-2.
	 * @param mb_row the row of the left top corner of the area to grab.
	 * @param mb_column the column of the left top corner of the area to grab.
	 * @param src the source YUV frame. 
	 * @param dst the destination YUV frame.
	 */
	 
	public final void copy_area(int mb_row, int mb_column, int src[][], int dst[][]) {

		try{ // YUCK

		int pos, pos1, i, j;
		int ypos = (mb_row << 4) + down_x;
		int xpos = (mb_column << 4) + right_x;
		int pos2, pos3, dst_pos, dst_pos_c;
		int pos_c, pos1_c, pos2_c, pos3_c;

		// Loop invariant elimination
		int[] src0 = src[0], src1 = src[1], src2 = src[2];
		int[] dst0 = dst[0], dst1 = dst[1], dst2 = dst[2];

		// LUMINANCE:

		dst_pos = pixel_per_lum_line * (mb_row << 4) + (mb_column << 4);

		if (!right_half_x && !down_half_x) {
			pos = pixel_per_lum_line * ypos + xpos;
			for (j = 16; j > 0; j--) {
				System.arraycopy(src0, pos, dst0, dst_pos, 16);
				pos += pixel_per_lum_line;
				dst_pos += pixel_per_lum_line;
			}
		}
		else if (!right_half_x && down_half_x)  {
			pos = pixel_per_lum_line * ypos + xpos;
			pos1 = pixel_per_lum_line * (ypos + 1) + xpos;
			for (j = 16; j > 0; j--) {
				for (i = 16; i > 0; i--) {
					dst0[dst_pos++] = (src0[pos++] + src0[pos1++]) >> 1;
				}
				pos += lum_y_incr; pos1 += lum_y_incr; dst_pos += lum_y_incr;
			}
		}
		else if (right_half_x && !down_half_x) {
			pos = pixel_per_lum_line * ypos + xpos;
			pos1 = pixel_per_lum_line * ypos + xpos + 1;
			for (j = 16; j > 0; j--) {
				for (i = 16; i > 0; i--) {
					dst0[dst_pos++] = (src0[pos++] + src0[pos1++]) >> 1;
				}
				pos += lum_y_incr; pos1 += lum_y_incr; dst_pos += lum_y_incr;
			}
		}
		else {
			pos = pixel_per_lum_line * ypos + xpos;
			pos1 = pixel_per_lum_line * (ypos + 1) + xpos;
			pos2 = pixel_per_lum_line * ypos + xpos + 1;
			pos3 = pixel_per_lum_line * (ypos + 1) + xpos + 1;
			for (j = 16; j > 0; j--) {
				for (i = 16; i > 0; i--) {
					dst0[dst_pos++] = (src0[pos++] + src0[pos1++] +
							  src0[pos2++] + src0[pos3++]) >> 2;
				}
				pos += lum_y_incr; pos1 += lum_y_incr; pos2 += lum_y_incr; pos3 += lum_y_incr;
				dst_pos += lum_y_incr;
			}
		}

		// CHROMINANCE:

		ypos = (mb_row << 3) + down_x_col;
		xpos = (mb_column << 3) + right_x_col;

		if (ypos < 0) ypos = 0;
		if (xpos < 0) xpos = 0;

		dst_pos = dst_pos_c = pixel_per_col_line * (mb_row << 3) + (mb_column << 3);
		pos = pixel_per_col_line * ypos + xpos;

		if (!right_half_x_col && !down_half_x_col) {
			pos = pixel_per_col_line * ypos + xpos;
			for (j = 8; j > 0; j--) {
				System.arraycopy(src1, pos, dst1, dst_pos, 8);
				System.arraycopy(src2, pos, dst2, dst_pos, 8);
				pos += pixel_per_col_line;
				dst_pos += pixel_per_col_line;
			}
		}
		else if (!right_half_x_col && !down_half_x_col) {
			pos = pixel_per_col_line * ypos + xpos;
			pos1 = pixel_per_col_line * (ypos + 1) + xpos;
			for (j = 8; j > 0; j--) {
				pos_c = pos; pos1_c = pos1;
				for (i = 8; i > 0; i--) {
					dst1[dst_pos++] = (src1[pos++] + src1[pos1++]) >> 1;
				}
				for (i = 8; i > 0; i--) {
					dst2[dst_pos_c++] = (src2[pos_c++] + src2[pos1_c++]) >> 1;
				}
				pos += col_y_incr; pos1 += col_y_incr;
				dst_pos += col_y_incr; dst_pos_c += col_y_incr;
			}
		}
		else if (right_half_x_col  && !down_half_x_col) {
			pos_c = pos = pixel_per_col_line * ypos + xpos;
			pos1_c = pos1 = pixel_per_col_line * ypos + xpos + 1;
			for (j = 8; j > 0; j--) {
				pos_c = pos; pos1_c = pos1;
				for (i = 8; i > 0; i--) {
					dst1[dst_pos++] = (src1[pos++] + src1[pos1++]) >> 1;
				}
				for (i = 8; i > 0; i--) {
					dst2[dst_pos_c++] = (src2[pos_c++] + src2[pos1_c++]) >> 1;
				}
				pos += col_y_incr; pos1 += col_y_incr;
				dst_pos += col_y_incr; dst_pos_c += col_y_incr;
				
				
			}
		}
		else {
			pos_c = pos = pixel_per_col_line * ypos + xpos;
			pos1_c = pos1 = pixel_per_col_line * (ypos + 1) + xpos;
			pos2_c = pos2 = pixel_per_col_line * ypos + xpos + 1;
			pos3_c = pos3 = pixel_per_col_line * (ypos + 1) + xpos + 1;
			for (j = 8; j > 0; j--) {
				pos_c = pos; pos1_c = pos1; pos2_c = pos2; pos3_c = pos3;
				for (i = 8; i > 0; i--) {
					dst1[dst_pos++] = (src1[pos++] + src1[pos1++] + src1[pos2++] + src1[pos3++]) >> 2;
				}
				for (i = 8; i > 0; i--) {
					dst2[dst_pos_c++] = (src2[pos_c++] + src2[pos1_c++] + src2[pos2_c++] + src2[pos3_c++]) >> 2;
				}
				pos += col_y_incr; pos1 += col_y_incr; pos2 += col_y_incr; pos3 += col_y_incr;
				dst_pos += col_y_incr; dst_pos_c += col_y_incr;
			}
		}

		} catch (Exception e) {
			error_count++;
			if (error_count < 5)
				System.out.println("Illegal area copy...");
			else if (error_count == 5)
				System.out.println("Ignoring further errors in motion_data...");
		}

	}

	/**
	 * The method "copy_unchanged" grabs the "src" and puts it to the same
	 * position in "dst".
	 * @param mb_row the row of the left top corner of the area to grab.
	 * @param mb_column the column of the left top corner of the area to grab.
	 * @param src the source YUV frame. 
	 * @param dst the destination YUV frame.
	 */

	public final void copy_unchanged(int mb_row, int mb_column, int src[][], int dst[][]) {

		try {

		int j;

		// Loop invariant elimination
		int[] src0 = src[0], src1 = src[1], src2 = src[2];
		int[] dst0 = dst[0], dst1 = dst[1], dst2 = dst[2];
		
		// LUMINANCE:

		int pos = pixel_per_lum_line * (mb_row << 4) + (mb_column << 4);

		for (j = 16; j > 0; j--) {
			System.arraycopy(src0, pos, dst0, pos, 16);
			pos += pixel_per_lum_line;
		}
		// CHROMINANCE:

		pos = pixel_per_col_line * (mb_row << 3) + (mb_column << 3);

		for (j = 8; j > 0; j--) {
			System.arraycopy(src1, pos, dst1, pos, 8);
			System.arraycopy(src2, pos, dst2, pos, 8);
			pos += pixel_per_col_line;
		}

		} catch (Exception e) {
			error_count++;
			if (error_count < 5)
				System.out.println("Illegal copy_unchanged...");
			else if (error_count == 5)
				System.out.println("Ignoring further errors in motion_data...");
		}

	}

	/**
	 * The method "put_area" gets the pixels from temporary storage "src"
	 * and adds them to the macroblock addressed by "mb_row" and "mb_column"
	 * @param mb_row the row of the left top corner of the area to grab.
	 * @param mb_column the column of the left top corner of the area to grab.
	 * @param src the source YUV frame. 
	 * @param dst the destination YUV frame.
	 */
	
	public final void put_area(int mb_row, int mb_column, int src[], int dst[][]) {

		int pos = pixel_per_lum_line * (mb_row << 4) + (mb_column << 4);
		int src_pos = 0, j;

		// Loop invariant elimination
		int[] dst0 = dst[0]; int[] dst1 = dst[1]; int[] dst2 = dst[2];

		for (j = 16; j > 0; j--) {
			System.arraycopy(src, src_pos, dst0, pos, 16);
			src_pos += 16; pos += pixel_per_lum_line;
		}

		pos = pixel_per_col_line * (mb_row << 3) + (mb_column << 3);

		for (j = 16; j > 0; j--) {
			System.arraycopy(src, src_pos, dst1, pos, 8);
			src_pos += 8;
			System.arraycopy(src, src_pos, dst2, pos, 8);
			src_pos += 8;
			pos += pixel_per_col_line;
		}

	}


	/**
	 * The method "put_area(2)" is called if both, a forward and a backward motion
	 * vector is supplied. In this case the method computes the average color of the
	 * 2 given areas "src1" and "src2" and adds the result(s) to the macro block
	 * addressed by "mb_row" and "mb_column".
	 * @param mb_row the row of the left top corner of the area to grab.
	 * @param mb_column the column of the left top corner of the area to grab.
	 * @param src1 first source YUV frame.
	 * @param src2 second source YUV frame. 
	 * @param dst the destination YUV frame.
	 */

	public final void put_area(int mb_row, int mb_column, int src1[], int src2[], int dst[][]) {

		int pos = pixel_per_lum_line * (mb_row << 4) + (mb_column << 4);
		int pos_c;
		int src_pos = 0;

		int i, j;

		// Loop invariant elimination
		int[] dst0 = dst[0], dst1 = dst[1], dst2 = dst[2];

		for (j = 16; j > 0; j--) {
			for (i = 16; i > 0; i--) {
					dst0[pos++] = (src1[src_pos] + src2[src_pos]) >> 1;
					src_pos++;
			}
			pos += lum_y_incr;
		}
		pos = pixel_per_col_line * (mb_row << 3) + (mb_column << 3);

		for (j = 8; j > 0; j--) {
			pos_c = pos;
			for (i = 8; i > 0; i--) {
					dst1[pos++] = (src1[src_pos] + src2[src_pos]) >> 1;
					src_pos++;
			}
			for (i = 8; i > 0; i--) {
					dst2[pos_c++] = (src1[src_pos] + src2[src_pos]) >> 1;
					src_pos++;
			}
			pos += col_y_incr;
		}
	}
}
